VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "TestFinder"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private mcol As Collection

Public Sub FindTests()
Dim component As Object

    For Each component In harness.book.VBProject.VBComponents
        CheckComponent component
    Next

End Sub

Public Property Get TestsFound() As Collection
    Set TestsFound = mcol
End Property

Private Sub CheckComponent(comp As Object)
        
    If TypeName(comp) <> "VBComponent" Then
        Exit Sub
    End If
    
    If isTestImplementor(comp) Then
        mcol.Add comp.Name
    End If

End Sub

Private Function isTestImplementor(component As Object) As Boolean

Dim theLines As Variant
Dim idx As Long
Dim line As String

    With component.CodeModule
        If .CountOfLines > 0 Then
            theLines = .lines(1, .CountOfLines)
        Else
            theLines = ""
        End If
    End With
    
    theLines = Split(theLines, vbCrLf)
    
    For idx = LBound(theLines) To UBound(theLines)
        line = CStr(theLines(idx))
        If LCase(line) Like "implements*testcase" Then
            isTestImplementor = True
            Exit Function
        End If
    
    Next

    isTestImplementor = False

End Function

Private Sub Class_Initialize()
    Set mcol = New Collection
End Sub
